//------------------------------------------------------------------------
//
//	CCGameBox is a game development library for iPhone and iPod Touch.
//
//	Licensed under the BSD license, see LICENSE in root for details.
// 
//	Copyright (c) 2009 James Hui (a.k.a. Dr.Watson)
// 
//	For latest updates, please visit http://www.cocoachina.com
//
//------------------------------------------------------------------------

#import "Wrapper.h"
#import "Texture2D.h"

#import "CCTexture.h"


CCTexture *CCTextureCreate(const char *filename, bool fullpath)
{
	
	NSString *name = [[NSString alloc] initWithUTF8String: filename];
	UIImage *image = nil;
	
	if (fullpath)
		image = [UIImage imageWithContentsOfFile:name];
	else
		image = [UIImage imageNamed: name];

	Texture2D *tex = [[Texture2D alloc] initWithImage: image];
	//[image release];

	CCTexture *texture = new CCTexture([tex name], tex.contentSize.width, tex.contentSize.height, tex.pixelsWide, tex.pixelsHigh);
		
	[tex release];

	return texture;
	
}


CCTexture *CCStringTextureCreate(const char *s, float w, float h, float size)
{
	NSString *str = [[NSString alloc] initWithUTF8String: s];
	
	Texture2D *tex = [[Texture2D alloc] initWithString:str dimensions:CGSizeMake(w, h) alignment:UITextAlignmentLeft fontName:@"Arial" fontSize:size];
	
	CCTexture *texture = new CCTexture([tex name], tex.contentSize.width, tex.contentSize.height, tex.pixelsWide, tex.pixelsHigh);
	
	[tex release];
	[str release];
	
	return texture;
	
}


CCTexture *CCFontTextureCreate(float w, float h, float size, float *charWidths, float *actualHeight)
{
	Texture2D *tex = [[Texture2D alloc] makeASCIIBitmapFont:CGSizeMake(w, h) fontName:@"Arial" fontSize:size charWidthArray:charWidths fontHeight:actualHeight];
	
	CCTexture *texture = new CCTexture([tex name], tex.contentSize.width, tex.contentSize.height, tex.pixelsWide, tex.pixelsHigh);
	
	[tex release];
	
	return texture;
	
}


const char *GetPath(const char *s, const char *directory)
{
	NSString *dir = nil;
	if (directory)
		dir = [[NSString alloc] initWithUTF8String: directory];
	NSString *name = [[NSString alloc] initWithUTF8String: s];
	NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil inDirectory:dir];
	
	return [path UTF8String];
	
}

